/*
 * Hello World by Krzysztof Kotarski
 * 18.12.2008
 *
 * Features:
 *  - blinking led connected to PB1
 *  - uart echo 
 *  - generate 42Hz 75% duty square signal on PB3
 */

#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "../lib/usart.h"

#define USART_BAUDRATE 19200
#define F_CLK 11059200
#define BAUD_PRESCALE (F_CLK/16/USART_BAUDRATE - 1)

unsigned char pwm;

void usart_rx_callback(unsigned char c)
{
	printf_P(PSTR("%c"), c);
}

int main (void)
{
	unsigned int c;

	usart_init(F_CLK,USART_BAUDRATE);
	usart_setup_stdio();
	printf_P(PSTR("Hello world!\n"));
	DDRB = _BV(PB1) | _BV(PB3);
	OCR0 = 192;
	TCCR0 |= _BV(WGM00) | _BV(WGM01) | _BV(COM01) | _BV(CS00) | _BV(CS02);
	sei();
	
	while(1)
	{
 	    int i;
	    for(i=0;i<0xffff>>1;i++);
	    
	    PORTB = (unsigned char)c & _BV(PB1);
	    c++;	
	}
}

